﻿@model AdminUserEditListModel
@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<section class="layui-larry-box">
    <div class="larry-personal">
        <div class="larry-personal-body clearfix">
            <form class="layui-form col-lg-5" id="form" method="post">

                <input type="hidden" name="Id" value="@Model.AdminUser.Id" />
                <div class="layui-form-item">
                    <label class="layui-form-label">管理员姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="Name" lay-verify="username|required" autocomplete="off" class="layui-input" value="@Model.AdminUser.Name" placeholder="请输入管理员姓名">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">昵称</label>
                    <div class="layui-input-block">
                        <input type="text" name="NickName" lay-verify="username|required" autocomplete="off" value="@Model.AdminUser.NickName" class="layui-input" placeholder="请输入管理员昵称">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">手机号码</label>
                    <div class="layui-input-block">
                        <input type="text" name="PhoneNum" value="@Model.AdminUser.PhoneNum" lay-verify="required|phone" autocomplete="off" class="layui-input" placeholder="输入手机号码">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" name="Email" value="@Model.AdminUser.Email" lay-verify="required|email" autocomplete="off" class="layui-input" placeholder="输入邮箱">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-block">
                        <input type="radio" name="Gender" value="true" title="男" checked="@(Model.AdminUser.Gender)" /><div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><span>男</span></div>

                        <input type="radio" name="Gender" value="false" title="女" checked="@(!Model.AdminUser.Gender)" />
                        <div class="layui-unselect layui-form-radio">
                            <i class="layui-anim layui-icon"></i>
                            <span>女</span>
                        </div>
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">添加头像</label>
                    <div class="layui-input-block">
                        <input type="file" title="添加头像" name="file" class="layui-upload-file">
                    </div>
                    <input type="hidden" id="ImgSrc" name="ImgSrc" lay-verify="upload" value="@Model.AdminUser.ImgSrc" />

                    <div class="layui-input-block">
                        <img src="@(Model.AdminUser.ImgSrc==null?null:"http://static.amortal.top/"+ Model.AdminUser.ImgSrc)" id="img" alt="请选择图片" height="50px;" />
                    </div>
                </div>



                <div class="layui-form-item">
                    <label class="layui-form-label">角色</label>
                    <div class="layui-input-block">
                        @foreach (var role in Model.Roles)
                        {
                            <input type="checkbox" checked="@Model.HROles.Any(e=>e.Id==role.Id)" name="Roles" id="role_@role.Id" value="@role.Id" title="@role.Name" />
                        }
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</section>

@section FooterScript{
    <script type="text/javascript">
        layui.use(['form', 'upload', 'jquery'], function () {
            var form = layui.form();
            layui.upload({
                url: '/AdminUser/Upload',//上传接口
                success: function (res) {
                    if (res.status == "error") {
                        layer.msg(res.errorMsg, { icon: 2, time: 1000 });
                    } else if (res.status == "ok") {
                        layer.msg("上传成功");
                        console.log(res.data);
                        $('#ImgSrc').attr("value", res.data);
                        $('#img').attr("src", "http://static.amortal.top/" + res.data);
                    } else if (res.status == "redirect") {
                        location.href = res.data;
                    } else {
                        layer.msg("错误");
                    }
                }
            });



            form.on('submit(demo1)', function (data) {
            
                var json = $('#form').serialize();
                console.log(json);

                //layer.msg(data.field);
                $.ajax({
                    url: "/AdminUser/Edit",
                    data: json,
                    dataType: "json",
                    type: "post",
                    success: function (res) {
                        if (res.status=="ok") {
                            parent.location.reload();
                        } else if (res.status == "error") {
                            layer.msg("错误："+res.errorMsg, { icon: 2, time: 1000 });
                        } else if (res.status=="redirect") {
                            location.href = res.data;
                        } else {
                            layer.msg("请求错误", { icon: 2, time: 1000 });
                        }
                    }
                });

                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });


        });

        var appConfig = {};
        
    </script>
}

